package com.cskaoyan.shopping.service.impl.zxw;

import com.cskaoyan.mall.dto.ItemDto;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.constants.GlobalConstants;
import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContentItem;
import com.cskaoyan.shopping.dal.persistence.ItemMapper;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dal.persistence.PanelMapper;
import com.cskaoyan.shopping.dto.AllProductResponse;
import com.cskaoyan.shopping.dto.PanelContentItemDto;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.form.PageRequest;
import com.cskaoyan.shopping.service.IProductService;
import com.cskaoyan.shopping.service.ZxwIProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author 曾添乐啦
 * @since 2023/01/09 22:08
 */
@Service
public class ZxwIProductServiceImpl implements ZxwIProductService {

    @Autowired
    ItemMapper itemMapper;


    @Autowired
    PanelMapper panelMapper;

    @Autowired
    PanelContentMapper panelContentMapper;

    @Autowired
    ContentConverter contentConverter;

    @Override
    public ProductDetailDto getProductDetail(Long id) {
        return null;
    }

    @Override
    public AllProductResponse getAllProduct(PageRequest pageInfo) {
        return null;
    }

    /**
     * @author 曾添乐啦
     * @since 2023/01/09 22:08
     */
    //查询推荐商品
    @Override
    public Set<PanelDto> getRecommendGoods() {
        //查询推荐商品
        List<PanelContentItem> panelContentItems = panelContentMapper.selectPanelContentAndProductWithPanelId(GlobalConstants.RECOMMEND_PANEL_ID);
        Panel panel = panelMapper.selectByPrimaryKey(GlobalConstants.RECOMMEND_PANEL_ID);

        // 类型转换
        List<PanelContentItemDto> panelContentItemDtos = contentConverter.panelContentItem2Dto(panelContentItems);
        PanelDto panelDto = contentConverter.panel2Dto(panel);


        panelDto.setPanelContentItems(panelContentItemDtos);

        Set<PanelDto> panelDtos = new HashSet<>();
        panelDtos.add(panelDto);
        return panelDtos;

    }


    @Override
    public List<ItemDto> getAllItems() {
        return null;
    }
}
